import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaRightMenu, WeaDialog, WeaFormItem, WeaSearchGroup, WeaSelect, WeaInputNumber, WeaBrowser } from "ecCom";
import { Button, } from "antd";
import { idsAndNamesToArr } from "../../../util/Util";

/**
 * 考核设置-考核结果分析共享设置-新增
 * jiansong 2019/6/18
 */
@inject("reportShareStore")
@observer
export default class ReportShareOperation extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.reportShareStore
    }

    render() {
        let { showUpdataDialog, closeForm, operation, loading } = this.store;
        const menu = [{
            key: 'save',
            icon: <i className='icon-coms-search' />,
            content: '保存',
            onClick: operation,
        }, {
            key: 'close',
            icon: <i className='icon-coms-search' />,
            content: '关闭',
            onClick: closeForm,
        }]
        let buttons = [
            <Button type="primary" loading={loading} onClick={operation}>确定</Button>,
            <Button type="ghost" onClick={closeForm}>取消</Button>
        ];
        return (
            <WeaDialog
                style={{ width: 840, height: 400 }}
                buttons={buttons}
                hasScroll
                title={"考核结果分析共享设置"}
                visible={showUpdataDialog}
                onCancel={closeForm}
            >
                <WeaRightMenu datas={menu}>
                    <WeaSearchGroup title="基础字段" items={this.getFormItem()} showGroup={true} col={1} />
                </WeaRightMenu>
            </WeaDialog>
        )
    }

    getFormItem() {
        let { form, onFormChange,sharetypeOption,sharelevelOption,rankOption } = this.store;
        let items = []
        items.push({
            com:
                <WeaFormItem label="共享类型" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaSelect
                        options={sharetypeOption}
                        value={form.sharetype}
                        onChange={(val) => onFormChange({ "sharetype": val, "relatedshareid": '', "relatedshareData": [] })}
                    />
                </WeaFormItem>
        });
        form.sharetype == '1' && items.push({
            com:
                <WeaFormItem label="人力资源" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        type={17}
                        viewAttr={3}
                        isSingle={false}
                        title={'人力资源'}
                        replaceDatas={form.relatedshareData}
                        onChange={(ids, names) => onFormChange({ "relatedshareid": ids, "relatedshareData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        form.sharetype == '2' && items.push({
            com:
                <WeaFormItem label="部门" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        type={57}
                        viewAttr={3}
                        isSingle={false}
                        title={'部门'}
                        replaceDatas={form.relatedshareData}
                        onChange={(ids, names) => onFormChange({ "relatedshareid": ids, "relatedshareData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        form.sharetype == '3' && items.push({
            com:
                <WeaFormItem label="角色" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        viewAttr={3}
                        type={267}
                        title={'角色'}
                        replaceDatas={form.relatedshareData}
                        onChange={(ids, names) => onFormChange({ "relatedshareid": ids, "relatedshareData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        form.sharetype == '3' && items.push({
            com:
                <WeaFormItem label="角色级别" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaSelect
                        options={rankOption}
                        value={form.rolelevel}
                        onChange={(val) => onFormChange({ "rolelevel": val })}
                    />
                </WeaFormItem>
        });
        (form.sharetype == '3' || form.sharetype == '2' || form.sharetype == '4') && items.push({
            com:
                <WeaFormItem label="安全级别" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaInputNumber
                        min={0}
                        max={100}
                        value={form.seclevel}
                        onChange={(val) => onFormChange({ 'seclevel': val })}
                    />
                </WeaFormItem>
        });
        items.push({
            com:
                <WeaFormItem label="共享级别" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaSelect
                        options={sharelevelOption}
                        value={form.sharelevel}
                        onChange={(val) => onFormChange({ "sharelevel": val, "mutiids": '', "mutiData": [] })}
                    />
                </WeaFormItem>
        });
        form.sharelevel == '6' && items.push({
            com:
                <WeaFormItem label="多部门" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        type={57}
                        viewAttr={3}
                        isSingle={false}
                        title={'多部门'}
                        replaceDatas={form.mutiData}
                        onChange={(ids, names) => onFormChange({ "mutiids": ids, "mutiData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        form.sharelevel == '8' && items.push({
            com:
                <WeaFormItem label="多分部" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        type={194}
                        viewAttr={3}
                        isSingle={false}
                        title={'多分部'}
                        replaceDatas={form.mutiData}
                        onChange={(ids, names) => onFormChange({ "mutiids": ids, "mutiData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        form.sharelevel == '9' && items.push({
            com:
                <WeaFormItem label="多人员" labelCol={{ span: 6 }} wrapperCol={{ span: 16 }}>
                    <WeaBrowser
                        type={17}
                        viewAttr={3}
                        isSingle={false}
                        title={'多人员'}
                        replaceDatas={form.mutiData}
                        onChange={(ids, names) => onFormChange({ "mutiids": ids, "mutiData": idsAndNamesToArr(ids, names) })}
                    />
                </WeaFormItem>
        });
        return items
    }
}